package org.example.pinda.base.entity;

import com.baomidou.mybatisplus.annotation.*;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotNull;
import javax.validation.groups.Default;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 超类基础实体
 *
 * @param <T> ID类型
 * @author ryan fawcett
 */
@Getter
@Setter
@ToString
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
public class SuperEntity<T> implements Serializable, Cloneable {

    public static final String FIELD_ID = "id";
    public static final String CREATE_TIME = "createTime";
    public static final String CREATE_USER = "create_user";

    @TableId(value = "id", type = IdType.INPUT)
    @ApiModelProperty("主键")
    @NotNull(message = "id不能为空", groups = SuperEntity.Update.class)
    protected T id;

    @TableField(value = "create_time", fill = FieldFill.INSERT)
    @ApiModelProperty("创建时间")
    protected LocalDateTime createTime;

    @TableField(value = "create_user", fill = FieldFill.INSERT)
    @ApiModelProperty("创建人ID")
    protected T createUser;

    @Override
    public Object clone() {
        try {
            return super.clone();
        } catch (CloneNotSupportedException e) {
            throw new AssertionError();
        }
    }

    /**
     * 更新验证组
     */
    public interface Update extends Default {
    }

    /**
     * 保存验证组
     */
    public interface Save extends Default {
    }

}
